package com.sikao.app.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import android.widget.ListView;
import android.widget.TextView;

import com.sikao.app.R;
import com.sikao.app.bean.CategoryAttrNewBean;

import com.sikao.app.utils.Utils;
import com.sikao.app.view.MyListView;

import java.util.ArrayList;
import java.util.List;
/**
 * 发布商品第二步 类型是5 下拉 有浮动值
 */
public class MllAddStepPricesTypeFiveItemNewAdapter extends BaseAdapter {

    private List<CategoryAttrNewBean.ResBean.AttrBean> objects = new ArrayList<CategoryAttrNewBean.ResBean.AttrBean>();

    private Context context;
    private LayoutInflater layoutInflater;

    public MllAddStepPricesTypeFiveItemNewAdapter(Context context, List<CategoryAttrNewBean.ResBean.AttrBean> objects) {
        this.context = context;
        this.layoutInflater = LayoutInflater.from(context);
        this.objects=objects;
    }

    @Override
    public int getCount() {
        return objects.size();
    }

    @Override
    public CategoryAttrNewBean.ResBean.AttrBean getItem(int position) {
        return objects.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {


        if (convertView == null) {
            convertView = layoutInflater.inflate(R.layout.mll_add_step_prices_type_five_new_item, null);
            convertView.setTag(new ViewHolder(convertView));
        }

        initializeViews(getItem(position), (ViewHolder) convertView.getTag(),position);

            return convertView;

    }

    private void initializeViews(CategoryAttrNewBean.ResBean.AttrBean object, ViewHolder holder,int position) {
        //TODO implement
        holder.tvName.setText(object.getName());
        //子项的adapter
        MllAddStepPricesTypeFiveChildItemNewAdapter mllAddStepPricesTypeFiveChildItemAdapter=new MllAddStepPricesTypeFiveChildItemNewAdapter(context,object,position);
        holder.mllAddStepPricesTypeFiveChild.setAdapter(mllAddStepPricesTypeFiveChildItemAdapter);
    }

    protected class ViewHolder {
        private TextView tvName;
        private  MyListView mllAddStepPricesTypeFiveChild;

        public ViewHolder(View view) {
            tvName = (TextView) view.findViewById(R.id.tv_name);
            mllAddStepPricesTypeFiveChild = (MyListView) view.findViewById(R.id.mll_add_step_prices_type_five_child);
        }
    }
}
